package com.ruoyi.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.CullenUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.FundLending;
import com.ruoyi.module.service.IFundLendingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资金拆借Controller
 *
 * @author fubojin
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/admin/lending")
public class FundLendingController extends BaseController {
    @Autowired
    private IFundLendingService fundLendingService;


    /**
     * 查询资金拆借列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FundLending fundLending) {
        startPage();
        List<FundLending> list = fundLendingService.selectFundLendingList(fundLending);
        return getDataTable(list);
    }

    /**
     * 导出资金拆借列表
     */
    @Log(title = "资金拆借", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FundLending fundLending) {
        List<FundLending> list = fundLendingService.selectFundLendingList(fundLending);
        ExcelUtil<FundLending> util = new ExcelUtil<FundLending>(FundLending.class);
        util.exportExcel(response, list, "资金拆借数据");
    }

    /**
     * 获取资金拆借详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fundLendingService.selectFundLendingById(id));
    }

    /**
     * 新增资金拆借
     */
    @Log(title = "资金拆借", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FundLending fundLending) {
        return toAjax(fundLendingService.insertFundLending(fundLending));
    }

    /**
     * 修改资金拆借
     */
    @Log(title = "资金拆借", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FundLending fundLending) {
        return toAjax(fundLendingService.updateFundLending(fundLending));
    }

    /**
     * 删除资金拆借
     */
    @Log(title = "资金拆借", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fundLendingService.deleteFundLendingByIds(ids));
    }


    /**
     * 提现审核（通过）
     */
    @PostMapping(value = "approve/{id}")
    public AjaxResult approve(@PathVariable("id") Long id) {
        return success(fundLendingService.approve(id));
    }

    /**
     * 提现审核（拒绝）
     */
    @PostMapping(value = "reject/{id}")
    public AjaxResult reject(@PathVariable("id") Long id, @RequestParam String reasonReason) {
        return success(fundLendingService.reject(id,reasonReason));
    }

    /**
     * 提现（取消）
     */
    @PostMapping(value = "cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id, @RequestParam String reasonReason) {
        return success(fundLendingService.cancel(id,reasonReason));
    }

}
